home *** CD-ROM | disk | FTP | other *** search
/ Hot Super Models / Hot Super Models.iso / mac / fixer.sit / fixer.c next >
C/C++ Source or Header  |  1990-03-14  |  3KB  |  137 lines

  1. /*
  2.  * fixer.c - Steve Hawley 3/90
  3.  * sdh@flash.bellcore.com
  4.  * fixer will patch PICT files created by Giffer 1.03 so that they can
  5.  * be displayed in Studio 8, or Image etc.
  6.  *
  7.  * The problem with giffer is that it redefines white and black (positions 0 and
  8.  * 255 in the colormap).  This is a bad thing to do, and confuses the heck out of
  9.  * the poor Macintosh.
  10.  *
  11.  * Fixer takes a stupid, but quick means at patching the files.  It copies the
  12.  * file, coercing color 0 to be white and color 255 to be black.  It doesn't parse
  13.  * the PICT file, so it won't work on anything but those created by Giffer 1.03.
  14.  * ie, I've only tested it on 1.03  --it might work on other versions, but don't
  15.  * hold your breath.
  16.  */
  17.  
  18.  
  19.  
  20. main()
  21. {
  22.     int inRef, outRef;
  23.  
  24.     InitGraf(&thePort);
  25.     InitFonts();
  26.     InitWindows();
  27.     TEInit();
  28.     InitMenus();
  29.     InitDialogs(0L);
  30.     SetCursor(&arrow);
  31.  
  32.     while((inRef = PickLoad()) != -1) {
  33.         if ((outRef = PickSave()) != -1) {
  34.             Thrash(inRef, outRef);
  35.             FSClose(inRef);
  36.             FSClose(outRef);
  37.         }
  38.     }
  39. }
  40.  
  41. PickLoad()
  42. {
  43.     static Point p = { 100, 100 };
  44.     SFReply myReply;
  45.     static OSType myTypes[] = {
  46.         'PICT'
  47.     };
  48.     int fRef;
  49.  
  50.     SFGetFile(p, "\PWhich file?", 0L, sizeof(myTypes)/sizeof(OSType), myTypes,
  51.         0L, &myReply);
  52.     if (myReply.good) {
  53.         if (FSOpen(myReply.fName, myReply.vRefNum, &fRef)) return(-1);
  54.         else return(fRef);
  55.     }
  56.     return(-1);
  57. }
  58.  
  59. PickSave()
  60. {
  61.     static Point p = { 100, 100 };
  62.     int fRef;
  63.     SFReply myReply;
  64.  
  65.     myReply.fType = 'PICT';
  66.     SFPutFile(p, "\PSave as:", "\p", 0L, &myReply);
  67.     if (myReply.good) {
  68.         Create(myReply.fName, myReply.vRefNum, '????', 'PICT');
  69.         if (FSOpen(myReply.fName, myReply.vRefNum, &fRef)) return(-1);
  70.         else return(fRef);
  71.     }
  72.     else return(-1);
  73. }
  74.  
  75. Thrash(from, to)
  76. int from, to;
  77. {
  78.     Ptr data;
  79.     long size, fileEOF, currMark, dataSize;
  80.     register int i;
  81.     register unsigned char *p;
  82.     struct {
  83.         unsigned int r, g, b;
  84.     } rgb;
  85.  
  86.     size = 624; /* 624 is the offset until 1st entry in colormap */
  87.     data = NewPtr(size);
  88.     FSRead(from, &size, data);
  89.     
  90.     size = 624;
  91.     FSWrite(to, &size, data);
  92.     
  93.     DisposPtr(data);
  94.     
  95.     size = sizeof(rgb);
  96.     FSRead(from, &size, &rgb);
  97.     rgb.r = 0xffff; /* force white */
  98.     rgb.g = 0xffff;
  99.     rgb.b = 0xffff;
  100.     size = sizeof(rgb);
  101.     FSWrite(to, &size, &rgb);
  102.  
  103.     size = 2034; /* offset to last entry in rgb table */
  104.     data = NewPtr(size);
  105.     FSRead(from, &size, data);
  106.     
  107.     size = 2034;
  108.     FSWrite(to, &size, data);
  109.     DisposPtr(data);
  110.  
  111.     size = sizeof(rgb);
  112.     FSRead(from, &size, &rgb);
  113.     rgb.r = 0; /* force black */
  114.     rgb.g = 0;
  115.     rgb.b = 0;
  116.     size = sizeof(rgb);
  117.     FSWrite(to, &size, &rgb);
  118.  
  119.     size = 18; /* offset to data start */
  120.     data = NewPtr(size);
  121.     FSRead(from, &size, data);
  122.     
  123.     size = 18;
  124.     FSWrite(to, &size, data);
  125.     DisposPtr(data);
  126.     
  127.     GetFPos(from, &currMark);
  128.     GetEOF(from, &fileEOF);
  129.         
  130.     data = NewPtr(16384L); /* nice big buffer */
  131.     do {
  132.         size = 16384;
  133.         FSRead(from, &size, data);
  134.         FSWrite(to, &size, data);
  135.     } while(size); /* copy until EOF */
  136.     DisposPtr(data);
  137. }